import 'dart:ui';

import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/modal/modal.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

import 'button/download_btn.dart';

showAppVersionUpModal(
  BuildContext context, {
  String version,
  bool forceUpdate,
  String downloadUrl,
  String content,
}) {
  showModal(
    context,
    builder: (context) => AppVersionModal(
      version: version,
      forceUpdate: forceUpdate,
      downloadUrl: downloadUrl,
      content: content,
    ),
    isShowCloseIcon: forceUpdate,
  );
}

class AppVersionModal extends StatefulWidget {
  final String version;
  final bool forceUpdate;
  final String downloadUrl;
  final String content;

  const AppVersionModal({
    this.version,
    this.forceUpdate,
    this.downloadUrl,
    this.content,
    Key key,
  }) : super(key: key);

  @override
  _AppVersionModalState createState() => _AppVersionModalState();
}

class _AppVersionModalState extends State<AppVersionModal> {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        return false;
      },
      child: Container(
        width: 600.w,
        height: 560.w,
        padding: EdgeInsets.only(top: 40.w, bottom: 35.w, left: 70.w, right: 70.w),
        child: Column(
          children: <Widget>[
            Text(
              '发现新版本${widget.version}',
              style: TextStyleConstant().normal_1_36,
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.symmetric(vertical: 40.w),
                child: SingleChildScrollView(
                  physics: BouncingScrollPhysics(),
                  child: Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      '${widget.content}',
                      style: TextStyleConstant().normal_1_28,
                    ),
                  ),
                ),
              ),
            ),
            DownloadButton(
              title: '立即更新',
              downloadUrl: widget.downloadUrl,
            ),
            if (!widget.forceUpdate)
              Container(
                margin: EdgeInsets.only(
                  top: 30.w,
                ),
                child: GestureDetector(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child: Text(
                    '暂不升级',
                    style: TextStyle(
                      fontSize: 32.sp,
                      color: ColorConstant.ff99,
                      decoration: TextDecoration.underline,
                    ),
                  ),
                ),
              )
          ],
        ),
      ),
    );
  }
}
